﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using myWallet.App_Code;

namespace myWallet
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitDdlSelectLanguage();
            }
        }

        protected void InitDdlSelectLanguage()
        {
            if (Session["lang"] != null)
            {
                ddlSelectLanguage.SelectedValue = Session["lang"].ToString();
            }
            else
            {
                if (HttpContext.Current.Response.Cookies["lang"] != null)
                {
                    ddlSelectLanguage.SelectedValue = HttpContext.Current.Response.Cookies["lang"].Value;
                    Session["lang"] = HttpContext.Current.Response.Cookies["lang"].Value;
                }
                else
                {
                    ddlSelectLanguage.SelectedValue = "en-US";
                    Session["lang"] = "en-US";
                    LanguageHelper.SetLanguage("en-US");
                }
            }
        }

        protected void ddlSelectLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlSelectLanguage.SelectedValue == "en-US")
            {
                LanguageHelper.SetLanguage("en-US");
                Response.Redirect(HttpContext.Current.Request.Url.PathAndQuery, false);
            }
            else if (ddlSelectLanguage.SelectedValue == "vi-VN")
            {
                LanguageHelper.SetLanguage("vi-VN");
                Response.Redirect(HttpContext.Current.Request.Url.PathAndQuery, false);
            }
        }
    }
}
